import {
	defineStore
} from 'pinia'
import {
	clone,
	cloneDeep
} from 'lodash'
import orderlist from "@/common/base/interface/orderlist.js"
export default defineStore('Interface', {
	state: () => ({
		updateAppInfo: null, //app更新的数据
		//商品列表
		...cloneDeep(orderlist.state),
	}),
	getters: {
		// getUserInfo:(state) => state.userInfo ,
	},
	actions: {
		...orderlist.actions,
		getUpdateAppInfo(info) { //app更新的方法
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, (widgetInfo = {}) => {
				uni.$u.http.get('/version/info', {
					params: {
						type: uni.$u.os() == "android" ? 1 : 2,
						version: widgetInfo.version
					}
				}).then(res => {
					console.log(`本地版本:${widgetInfo.version}`, res.download_url)
					this.updateAppInfo = res
				})
			});
			// #endif
		}
		
	}
})

function flatten(arr) {
	var res = [];
	arr.map(item => {
		if (Array.isArray(item.children)) {
			// console.log(item.children)
			res = res.concat(flatten(item.children));
			res.push(item)
			// console.log(res)
		} else {
			res.push(item);
		}
	});
	return res;
}